package com.santiao.publics.util.oaid;

import android.content.Context;
import android.util.Log;

import com.huawei.hms.ads.identifier.AdvertisingIdClient;
import com.santiao.publics.config.Const;
import com.santiao.publics.util.SharedPreferencesUtil;


public class DemoHelperHuawei {

    public void getOaid(AppIdsUpdater appIdsUpdater, Context mContext){
        /**
         * 在非UI线程获取设备标识信息
         */
//        new Thread() {
//            @Override
//            public void run() {
                String oaid = null;
                try {
                    AdvertisingIdClient.Info info = AdvertisingIdClient.getAdvertisingIdInfo(mContext);
                    if (null != info) {
                        oaid = info.getId();
                        Log.i(Const.TAG, "info id=" + info.getId() +
                                ", isLimitAdTrackingEnabled=" + info.isLimitAdTrackingEnabled());
                    }
                } catch (Exception e) {
                    Log.i(Const.TAG, "getAdvertisingIdInfo Exception: " + e.toString());
                }finally {
                    if (oaid == null || oaid.isEmpty()) {
                    }else{
                        SharedPreferencesUtil.saveString("oaidHw", oaid);

                    }
                    appIdsUpdater.onIdsValid(oaid);
                }
//            }
//        };
    }


    public interface AppIdsUpdater {
        void onIdsValid(String oaid);
    }
}
